home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / windows / winsock.zip / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1992-06-23  |  23KB  |  800 lines

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2.  *
  3.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  4.  * of the University of California.  All rights reserved.  The
  5.  * Berkeley Software License Agreement specifies the terms and
  6.  * conditions for redistribution.
  7.  */
  8.  
  9. #ifndef _WINSOCKAPI_
  10. #define _WINSOCKAPI_
  11.  
  12. /*
  13.  * Pull in WINDOWS.H if necessary
  14.  */
  15. #ifndef _INC_WINDOWS
  16. #include <windows.h>
  17. #endif /* _INC_WINDOWS */
  18.  
  19. /*
  20.  * Basic system type definitions, taken from the BSD file sys/types.h.
  21.  */
  22. typedef unsigned char    u_char;
  23. typedef unsigned short    u_short;
  24. typedef unsigned int    u_int;
  25. typedef unsigned long    u_long;
  26.  
  27. /*
  28.  * The new type to be used in all
  29.  * instances which refer to sockets.
  30.  */
  31. typedef u_int        SOCKET;
  32.  
  33. /*
  34.  * Select uses arrays of SOCKETs.  These macros manipulate such
  35.  * arrays.  FD_SETSIZE may be defined by the user before including
  36.  * this file, but the default here should be >= 64.
  37.  *
  38.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  39.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE. 
  40.  */
  41. #ifndef FD_SETSIZE
  42. #define FD_SETSIZE    64
  43. #endif /* FD_SETSIZE */
  44.  
  45. typedef struct fd_set {
  46.     u_short fd_count;        /* how many are SET? */
  47.     SOCKET    fd_array[FD_SETSIZE];    /* an array of SOCKETs */
  48. } fd_set;
  49.  
  50. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  51.  
  52. #define FD_CLR(fd, set) { \
  53.     u_int __i; \
  54.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  55.     if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  56.         while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  57.         ((fd_set FAR *)(set))->fd_array[__i] = \
  58.             ((fd_set FAR*)(set))->fd_array[__i+1]; \
  59.         __i++; \
  60.         } \
  61.         ((fd_set FAR *)(set))->fd_count--; \
  62.         break; \
  63.     } \
  64.     } \
  65. }
  66.  
  67. #define FD_SET(fd, set) { \
  68.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  69.     ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  70. }
  71.  
  72. #define FD_ZERO(set) ((fd_set FAR *)(set))->fd_count=0
  73.  
  74. #define FD_ISSET(fd, set) __WSAFDIsSet((int)fd, (fd_set FAR *)set)
  75.  
  76. /*
  77.  * Structure used in select() call, taken from the BSD file sys/time.h.
  78.  */
  79. struct timeval {
  80.     long    tv_sec;        /* seconds */
  81.     long    tv_usec;    /* and microseconds */
  82. };
  83.  
  84. /*
  85.  * Operations on timevals.
  86.  *
  87.  * NB: timercmp does not work for >= or <=.
  88.  */
  89. #define timerisset(tvp)        ((tvp)->tv_sec || (tvp)->tv_usec)
  90. #define timercmp(tvp, uvp, cmp) \
  91.     ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  92.      (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  93. #define timerclear(tvp)        (tvp)->tv_sec = (tvp)->tv_usec = 0
  94.  
  95. /*
  96.  * Commands for ioctlsocket(),    taken from the BSD file fcntl.h.
  97.  *
  98.  *
  99.  * Ioctl's have the command encoded in the lower word,
  100.  * and the size of any in or out parameters in the upper
  101.  * word.  The high 2 bits of the upper word are used
  102.  * to encode the in/out status of the parameter; for now
  103.  * we restrict parameters to at most 128 bytes.
  104.  */
  105. #define IOCPARM_MASK    0x7f        /* parameters must be < 128 bytes */
  106. #define IOC_VOID    0x20000000    /* no parameters */
  107. #define IOC_OUT        0x40000000    /* copy out parameters */
  108. #define IOC_IN        0x80000000    /* copy in parameters */
  109. #define IOC_INOUT    (IOC_IN|IOC_OUT)
  110.                     /* 0x20000000 distinguishes new &
  111.                        old ioctl's */
  112. #define _IO(x,y)    (IOC_VOID|('x'<<8)|y)
  113.  
  114. #define _IOR(x,y,t)    (IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|('x'<<8)|y)
  115.  
  116. #define _IOW(x,y,t)    (IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|('x'<<8)|y)
  117.  
  118. #define FIONREAD    _IOR(f, 127, int)    /* get # bytes to read */
  119. #define FIONBIO        _IOW(f, 126, int)    /* set/clear non-blocking i/o */
  120. #define FIOASYNC    _IOW(f, 125, int)    /* set/clear async i/o */
  121.  
  122. /* Socket I/O Controls */
  123. #define SIOCSHIWAT  _IOW(s,  0, int)    /* set high watermark */
  124. #define SIOCGHIWAT  _IOR(s,  1, int)    /* get high watermark */
  125. #define SIOCSLOWAT  _IOW(s,  2, int)    /* set low watermark */
  126. #define SIOCGLOWAT  _IOR(s,  3, int)    /* get low watermark */
  127. #define SIOCATMARK  _IOR(s,  7, int)    /* at oob mark? */
  128.  
  129. /*
  130.  * Structures returned by network data base library, taken from the
  131.  * BSD file netdb.h.  All addresses are supplied in host order, and
  132.  * returned in network order (suitable for use in system calls).
  133.  */
  134.  
  135. struct    hostent {
  136.     char    FAR * h_name;        /* official name of host */
  137.     char    FAR * FAR * h_aliases;    /* alias list */
  138.     int    h_addrtype;        /* host address type */
  139.     int    h_length;        /* length of address */
  140.     char    FAR * FAR * h_addr_list; /* list of addresses */
  141. #define h_addr    h_addr_list[0]        /* address, for backward compat */
  142. };
  143.  
  144. /*
  145.  * It is assumed here that a network number
  146.  * fits in 32 bits.
  147.  */
  148. struct    netent {
  149.     char    FAR * n_name;        /* official name of net */
  150.     char    FAR * FAR * n_aliases;    /* alias list */
  151.     int    n_addrtype;        /* net address type */
  152.     u_long    n_net;            /* network # */
  153. };
  154.  
  155. struct    servent {
  156.     char    FAR * s_name;        /* official service name */
  157.     char    FAR * FAR * s_aliases;    /* alias list */
  158.     int    s_port;            /* port # */
  159.     char    FAR * s_proto;        /* protocol to use */
  160. };
  161.  
  162. struct    protoent {
  163.     char    FAR * p_name;        /* official protocol name */
  164.     char    FAR * FAR * p_aliases;    /* alias list */
  165.     int    p_proto;        /* protocol # */
  166. };
  167.  
  168. /*
  169.  * Constants and structures defined by the internet system,
  170.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  171.  */
  172.  
  173. /*
  174.  * Protocols
  175.  */
  176. #define IPPROTO_IP        0        /* dummy for IP */
  177. #define IPPROTO_ICMP        1        /* control message protocol */
  178. #define IPPROTO_GGP        2        /* gateway^2 (deprecated) */
  179. #define IPPROTO_TCP        6        /* tcp */
  180. #define IPPROTO_PUP        12        /* pup */
  181. #define IPPROTO_UDP        17        /* user datagram protocol */
  182. #define IPPROTO_IDP        22        /* xns idp */
  183. #define IPPROTO_ND        77        /* UNOFFICIAL net disk proto */
  184.  
  185. #define IPPROTO_RAW        255        /* raw IP packet */
  186. #define IPPROTO_MAX        256
  187.  
  188. /*
  189.  * Port/socket numbers: network standard functions
  190.  */
  191. #define IPPORT_ECHO        7
  192. #define IPPORT_DISCARD        9
  193. #define IPPORT_SYSTAT        11
  194. #define IPPORT_DAYTIME        13
  195. #define IPPORT_NETSTAT        15
  196. #define IPPORT_FTP        21
  197. #define IPPORT_TELNET        23
  198. #define IPPORT_SMTP        25
  199. #define IPPORT_TIMESERVER    37
  200. #define IPPORT_NAMESERVER    42
  201. #define IPPORT_WHOIS        43
  202. #define IPPORT_MTP        57
  203.  
  204. /*
  205.  * Port/socket numbers: host specific functions
  206.  */
  207. #define IPPORT_TFTP        69
  208. #define IPPORT_RJE        77
  209. #define IPPORT_FINGER        79
  210. #define IPPORT_TTYLINK        87
  211. #define IPPORT_SUPDUP        95
  212.  
  213. /*
  214.  * UNIX TCP sockets
  215.  */
  216. #define IPPORT_EXECSERVER    512
  217. #define IPPORT_LOGINSERVER    513
  218. #define IPPORT_CMDSERVER    514
  219. #define IPPORT_EFSSERVER    520
  220.  
  221. /*
  222.  * UNIX UDP sockets
  223.  */
  224. #define IPPORT_BIFFUDP        512
  225. #define IPPORT_WHOSERVER    513
  226. #define IPPORT_ROUTESERVER    520
  227.                     /* 520+1 also used */
  228.  
  229. /*
  230.  * Ports < IPPORT_RESERVED are reserved for
  231.  * privileged processes (e.g. root).
  232.  */
  233. #define IPPORT_RESERVED        1024
  234.  
  235. /*
  236.  * Link numbers
  237.  */
  238. #define IMPLINK_IP        155
  239. #define IMPLINK_LOWEXPER    156
  240. #define IMPLINK_HIGHEXPER    158
  241.  
  242. /*
  243.  * Internet address (old style... should be updated)
  244.  */
  245. struct in_addr {
  246.     union {
  247.         struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  248.         struct { u_short s_w1,s_w2; } S_un_w;
  249.         u_long S_addr;
  250.     } S_un;
  251. #define s_addr    S_un.S_addr
  252.                 /* can be used for most tcp & ip code */
  253. #define s_host    S_un.S_un_b.s_b2
  254.                 /* host on imp */
  255. #define s_net    S_un.S_un_b.s_b1
  256.                 /* network */
  257. #define s_imp    S_un.S_un_w.s_w2
  258.                 /* imp */
  259. #define s_impno S_un.S_un_b.s_b4
  260.                 /* imp # */
  261. #define s_lh    S_un.S_un_b.s_b3
  262.                 /* logical host */
  263. };
  264.  
  265. /*
  266.  * Definitions of bits in internet address integers.
  267.  * On subnets, the decomposition of addresses to host and net parts
  268.  * is done according to subnet mask, not the masks here.
  269.  */
  270. #define IN_CLASSA(i)        (((long)(i) & 0x80000000) == 0)
  271. #define IN_CLASSA_NET        0xff000000
  272. #define IN_CLASSA_NSHIFT    24
  273. #define IN_CLASSA_HOST        0x00ffffff
  274. #define IN_CLASSA_MAX        128
  275.  
  276. #define IN_CLASSB(i)        (((long)(i) & 0xc0000000) == 0x80000000)
  277. #define IN_CLASSB_NET        0xffff0000
  278. #define IN_CLASSB_NSHIFT    16
  279. #define IN_CLASSB_HOST        0x0000ffff
  280. #define IN_CLASSB_MAX        65536
  281.  
  282. #define IN_CLASSC(i)        (((long)(i) & 0xc0000000) == 0xc0000000)
  283. #define IN_CLASSC_NET        0xffffff00
  284. #define IN_CLASSC_NSHIFT    8
  285. #define IN_CLASSC_HOST        0x000000ff
  286.  
  287. #define INADDR_ANY        (u_long)0x00000000
  288. #define INADDR_LOOPBACK        0x7f000001
  289. #define INADDR_BROADCAST    (u_long)0xffffffff    /* must be masked */
  290. #define INADDR_NONE        0xffffffff        /* -1 return */
  291.  
  292. /*
  293.  * Socket address, internet style.
  294.  */
  295. struct sockaddr_in {
  296.     short    sin_family;
  297.     u_short sin_port;
  298.     struct    in_addr sin_addr;
  299.     char    sin_zero[8];
  300. };
  301.  
  302. #define WSADESCRIPTION_LEN    256
  303. #define WSASYS_STATUS_LEN    128
  304.  
  305. typedef struct WSAData {
  306.     WORD            wVersion;
  307.     WORD            wHighVersion;
  308.     char            szDescription[WSADESCRIPTION_LEN+1];
  309.     char            szSystemStatus[WSASYS_STATUS_LEN+1];
  310.     int            iMaxSockets;
  311.     int            iMaxUdpDg;
  312.     char FAR *        lpVendorInfo;
  313. } WSADATA;
  314.  
  315. typedef WSADATA FAR *LPWSADATA;
  316.  
  317. /*
  318.  * Options for use with [gs]etsockopt at the IP level.
  319.  */
  320. #define IP_OPTIONS    1        /* set/get IP per-packet options */
  321.  
  322. /*
  323.  * Definitions related to sockets: types, address families, options,
  324.  * taken from the BSD file sys/socket.h.
  325.  */
  326.  
  327. /*
  328.  * This is used instead of -1, since the
  329.  * SOCKET type is unsigned.
  330.  */
  331. #define INVALID_SOCKET    (SOCKET)(~0)
  332. #define SOCKET_ERROR        (-1)
  333.  
  334. /*
  335.  * Types
  336.  */
  337. #define SOCK_STREAM    1        /* stream socket */
  338. #define SOCK_DGRAM    2        /* datagram socket */
  339. #define SOCK_RAW    3        /* raw-protocol interface */
  340. #define SOCK_RDM    4        /* reliably-delivered message */
  341. #define SOCK_SEQPACKET    5        /* sequenced packet stream */
  342.  
  343. /*
  344.  * Option flags per-socket.
  345.  */
  346. #define SO_DEBUG    0x0001        /* turn on debugging info recording */
  347. #define SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  348. #define SO_REUSEADDR    0x0004        /* allow local address reuse */
  349. #define SO_KEEPALIVE    0x0008        /* keep connections alive */
  350. #define SO_DONTROUTE    0x0010        /* just use interface addresses */
  351. #define SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  352. #define SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  353. #define SO_LINGER    0x0080        /* linger on close if data present */
  354. #define SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  355.  
  356. #define SO_DONTLINGER    (u_int)(~SO_LINGER)
  357.  
  358. /*
  359.  * Additional options.
  360.  */
  361. #define SO_SNDBUF    0x1001        /* send buffer size */
  362. #define SO_RCVBUF    0x1002        /* receive buffer size */
  363. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  364. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  365. #define SO_SNDTIMEO    0x1005        /* send timeout */
  366. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  367. #define SO_ERROR    0x1007        /* get error status and clear */
  368. #define SO_TYPE        0x1008        /* get socket type */
  369.  
  370. /*
  371.  * Address families.
  372.  */
  373. #define AF_UNSPEC    0        /* unspecified */
  374. #define AF_UNIX        1        /* local to host (pipes, portals) */
  375. #define AF_INET        2        /* internetwork: UDP, TCP, etc. */
  376. #define AF_IMPLINK    3        /* arpanet imp addresses */
  377. #define AF_PUP        4        /* pup protocols: e.g. BSP */
  378. #define AF_CHAOS    5        /* mit CHAOS protocols */
  379. #define AF_NS        6        /* XEROX NS protocols */
  380. #define AF_NBS        7        /* nbs protocols */
  381. #define AF_ECMA        8        /* european computer manufacturers */
  382. #define AF_DATAKIT    9        /* datakit protocols */
  383. #define AF_CCITT    10        /* CCITT protocols, X.25 etc */
  384. #define AF_SNA        11        /* IBM SNA */
  385. #define AF_DECnet    12        /* DECnet */
  386. #define AF_DLI        13        /* Direct data link interface */
  387. #define AF_LAT        14        /* LAT */
  388. #define AF_HYLINK    15        /* NSC Hyperchannel */
  389. #define AF_APPLETALK    16        /* AppleTalk */
  390.  
  391. #define AF_MAX        17
  392.  
  393. /*
  394.  * Structure used by kernel to store most
  395.  * addresses.
  396.  */
  397. struct sockaddr {
  398.     u_short sa_family;        /* address family */
  399.     char    sa_data[14];        /* up to 14 bytes of direct address */
  400. };
  401.  
  402. /*
  403.  * Structure used by kernel to pass protocol
  404.  * information in raw sockets.
  405.  */
  406. struct sockproto {
  407.     u_short sp_family;        /* address family */
  408.     u_short sp_protocol;        /* protocol */
  409. };
  410.  
  411. /*
  412.  * Protocol families, same as address families for now.
  413.  */
  414. #define PF_UNSPEC    AF_UNSPEC
  415. #define PF_UNIX        AF_UNIX
  416. #define PF_INET        AF_INET
  417. #define PF_IMPLINK    AF_IMPLINK
  418. #define PF_PUP        AF_PUP
  419. #define PF_CHAOS    AF_CHAOS
  420. #define PF_NS        AF_NS
  421. #define PF_NBS        AF_NBS
  422. #define PF_ECMA        AF_ECMA
  423. #define PF_DATAKIT    AF_DATAKIT
  424. #define PF_CCITT    AF_CCITT
  425. #define PF_SNA        AF_SNA
  426. #define PF_DECnet    AF_DECnet
  427. #define PF_DLI        AF_DLI
  428. #define PF_LAT        AF_LAT
  429. #define PF_HYLINK    AF_HYLINK
  430. #define PF_APPLETALK    AF_APPLETALK
  431.  
  432. #define PF_MAX        AF_MAX
  433.  
  434. /*
  435.  * Structure used for manipulating linger option.
  436.  */
  437. struct    linger {
  438.     u_short l_onoff;        /* option on/off */
  439.     u_short l_linger;        /* linger time */
  440. };
  441.  
  442. /*
  443.  * Level number for (get/set)sockopt() to apply to socket itself.
  444.  */
  445. #define SOL_SOCKET    0xffff        /* options for socket level */
  446.  
  447. /*
  448.  * Maximum queue length specifiable by listen.
  449.  */
  450. #define SOMAXCONN    5
  451.  
  452. #define MSG_OOB        0x1        /* process out-of-band data */
  453. #define MSG_PEEK    0x2        /* peek at incoming message */
  454. #define MSG_DONTROUTE    0x4        /* send without using routing tables */
  455.  
  456. #define MSG_MAXIOVLEN    16
  457.  
  458. /*
  459.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  460.  */
  461. #define MAXGETHOSTSTRUCT    1024
  462.  
  463. /*
  464.  * Define flags to be used with the WSAAsyncSelect() call.
  465.  */
  466. #define FD_READ        0x01
  467. #define FD_WRITE    0x02
  468. #define FD_OOB        0x04
  469. #define FD_ACCEPT    0x08
  470. #define FD_CONNECT    0x10
  471. #define FD_CLOSE    0x20
  472.  
  473. /*
  474.  * All Windows Sockets error constants are biased by WSABASEERR from
  475.  * the "normal"
  476.  */
  477. #define WSABASEERR        10000
  478. /*
  479.  * Windows Sockets definitions of regular Microsoft C error constants
  480.  */
  481. #define WSAEINTR        (WSABASEERR+4)
  482. #define WSAEBADF        (WSABASEERR+9)
  483. #define WSAEFAULT        (WSABASEERR+14)
  484. #define WSAEINVAL        (WSABASEERR+22)
  485. #define WSAEMFILE        (WSABASEERR+24)
  486.  
  487. /*
  488.  * Windows Sockets definitions of regular Berkeley error constants
  489.  */
  490. #define WSAEWOULDBLOCK        (WSABASEERR+35)
  491. #define WSAEINPROGRESS        (WSABASEERR+36)
  492. #define WSAEALREADY        (WSABASEERR+37)
  493. #define WSAENOTSOCK        (WSABASEERR+38)
  494. #define WSAEDESTADDRREQ        (WSABASEERR+39)
  495. #define WSAEMSGSIZE        (WSABASEERR+40)
  496. #define WSAEPROTOTYPE        (WSABASEERR+41)
  497. #define WSAENOPROTOOPT        (WSABASEERR+42)
  498. #define WSAEPROTONOSUPPORT    (WSABASEERR+43)
  499. #define WSAESOCKTNOSUPPORT    (WSABASEERR+44)
  500. #define WSAEOPNOTSUPP        (WSABASEERR+45)
  501. #define WSAEPFNOSUPPORT        (WSABASEERR+46)
  502. #define WSAEAFNOSUPPORT        (WSABASEERR+47)
  503. #define WSAEADDRINUSE        (WSABASEERR+48)
  504. #define WSAEADDRNOTAVAIL    (WSABASEERR+49)
  505. #define WSAENETDOWN        (WSABASEERR+50)
  506. #define WSAENETUNREACH        (WSABASEERR+51)
  507. #define WSAENETRESET        (WSABASEERR+52)
  508. #define WSAECONNABORTED        (WSABASEERR+53)
  509. #define WSAECONNRESET        (WSABASEERR+54)
  510. #define WSAENOBUFS        (WSABASEERR+55)
  511. #define WSAEISCONN        (WSABASEERR+56)
  512. #define WSAENOTCONN        (WSABASEERR+57)
  513. #define WSAESHUTDOWN        (WSABASEERR+58)
  514. #define WSAETOOMANYREFS        (WSABASEERR+59)
  515. #define WSAETIMEDOUT        (WSABASEERR+60)
  516. #define WSAECONNREFUSED        (WSABASEERR+61)
  517. #define WSAELOOP        (WSABASEERR+62)
  518. #define WSAENAMETOOLONG        (WSABASEERR+63)
  519. #define WSAEHOSTDOWN        (WSABASEERR+64)
  520. #define WSAEHOSTUNREACH        (WSABASEERR+65)
  521. #define WSAENOTEMPTY        (WSABASEERR+66)
  522. #define WSAEPROCLIM        (WSABASEERR+67)
  523. #define WSAEUSERS        (WSABASEERR+68)
  524. #define WSAEDQUOT        (WSABASEERR+69)
  525. #define WSAESTALE        (WSABASEERR+70)
  526. #define WSAEREMOTE        (WSABASEERR+71)
  527.  
  528. /*
  529.  * Extended Windows Sockets error constant definitions
  530.  */
  531. #define WSASYSNOTREADY        (WSABASEERR+91)
  532. #define WSAVERNOTSUPPORTED    (WSABASEERR+92)
  533. #define WSANOTINITIALISED    (WSABASEERR+93)
  534.  
  535. /*
  536.  * Error return codes from gethostbyname() and gethostbyaddr()
  537.  * (when using the resolver). Note that these errors are
  538.  * retrieved via WSAGetLastError() and must therefore follow
  539.  * the rules for avoiding clashes with error numbers from
  540.  * specific implementations or language run-time systems.
  541.  * For this reason the codes are based at WSABASEERR+1001.
  542.  * Note also that [WSA]NO_ADDRESS is defined only for
  543.  * compatibility purposes.
  544.  */
  545.  
  546. #define h_errno        WSAGetLastError()
  547.  
  548. /* Authoritative Answer: Host not found */
  549. #define WSAHOST_NOT_FOUND    (WSABASEERR+1001)
  550. #define HOST_NOT_FOUND        WSAHOST_NOT_FOUND
  551.  
  552. /* Non-Authoritative: Host not found, or SERVERFAIL */
  553. #define WSATRY_AGAIN        (WSABASEERR+1002)
  554. #define TRY_AGAIN        WSATRY_AGAIN
  555.  
  556. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  557. #define WSANO_RECOVERY        (WSABASEERR+1003)
  558. #define NO_RECOVERY        WSANO_RECOVERY
  559.  
  560. /* Valid name, no data record of requested type */
  561. #define WSANO_DATA        (WSABASEERR+1004)
  562. #define NO_DATA            WSANO_DATA
  563.  
  564. /* no address, look for MX record */
  565. #define WSANO_ADDRESS        WSANO_DATA
  566. #define NO_ADDRESS        WSANO_ADDRESS
  567.  
  568. /*
  569.  * Windows Sockets errors redefined as regular Berkeley error constants
  570.  */
  571. #define EWOULDBLOCK        WSAEWOULDBLOCK
  572. #define EINPROGRESS        WSAEINPROGRESS
  573. #define EALREADY        WSAEALREADY
  574. #define ENOTSOCK        WSAENOTSOCK
  575. #define EDESTADDRREQ        WSAEDESTADDRREQ
  576. #define EMSGSIZE        WSAEMSGSIZE
  577. #define EPROTOTYPE        WSAEPROTOTYPE
  578. #define ENOPROTOOPT        WSAENOPROTOOPT
  579. #define EPROTONOSUPPORT        WSAEPROTONOSUPPORT
  580. #define ESOCKTNOSUPPORT        WSAESOCKTNOSUPPORT
  581. #define EOPNOTSUPP        WSAEOPNOTSUPP
  582. #define EPFNOSUPPORT        WSAEPFNOSUPPORT
  583. #define EAFNOSUPPORT        WSAEAFNOSUPPORT
  584. #define EADDRINUSE        WSAEADDRINUSE
  585. #define EADDRNOTAVAIL        WSAEADDRNOTAVAIL
  586. #define ENETDOWN        WSAENETDOWN
  587. #define ENETUNREACH        WSAENETUNREACH
  588. #define ENETRESET        WSAENETRESET
  589. #define ECONNABORTED        WSAECONNABORTED
  590. #define ECONNRESET        WSAECONNRESET
  591. #define ENOBUFS            WSAENOBUFS
  592. #define EISCONN            WSAEISCONN
  593. #define ENOTCONN        WSAENOTCONN
  594. #define ESHUTDOWN        WSAESHUTDOWN
  595. #define ETOOMANYREFS        WSAETOOMANYREFS
  596. #define ETIMEDOUT        WSAETIMEDOUT
  597. #define ECONNREFUSED        WSAECONNREFUSED
  598. #define ELOOP            WSAELOOP
  599. #define ENAMETOOLONG        WSAENAMETOOLONG
  600. #define EHOSTDOWN        WSAEHOSTDOWN
  601. #define EHOSTUNREACH        WSAEHOSTUNREACH
  602. #define ENOTEMPTY        WSAENOTEMPTY
  603. #define EPROCLIM        WSAEPROCLIM
  604. #define EUSERS            WSAEUSERS
  605. #define EDQUOT            WSAEDQUOT
  606. #define ESTALE            WSAESTALE
  607. #define EREMOTE            WSAEREMOTE
  608.  
  609. /* Socket function prototypes */
  610.  
  611. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  612.               int FAR *addrlen);
  613.  
  614. int PASCAL FAR bind (SOCKET s, struct sockaddr FAR *addr, int namelen);
  615.  
  616. int PASCAL FAR closesocket (SOCKET s);
  617.  
  618. int PASCAL FAR connect (SOCKET s, struct sockaddr FAR *name, int namelen);
  619.  
  620. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  621.  
  622. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  623.                 int FAR * namelen);
  624.  
  625. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  626.                 int FAR * namelen);
  627.  
  628. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  629.                char FAR * optval, int FAR *optlen);
  630.  
  631. u_long PASCAL FAR htonl (u_long hostlong);
  632.  
  633. u_short PASCAL FAR htons (u_short hostshort);
  634.  
  635. struct in_addr PASCAL FAR inet_addr (char FAR * cp);
  636.  
  637. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  638.  
  639. int PASCAL FAR listen (SOCKET s, int backlog);
  640.  
  641. u_long PASCAL FAR ntohl (u_long netlong);
  642.  
  643. u_short PASCAL FAR ntohs (u_short netshort);
  644.  
  645. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  646.  
  647. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  648.              struct sockaddr FAR *from, int FAR * fromlen);
  649.  
  650. long PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set far *writefds,
  651.         fd_set FAR *exceptfds, struct timeval far *timeout);
  652.  
  653. int PASCAL FAR send (SOCKET s, char FAR * buf, int len, int flags);
  654.  
  655. int PASCAL FAR sendto (SOCKET s, char FAR * buf, int len, int flags,
  656.                struct sockaddr FAR *to, int tolen);
  657.  
  658. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  659.                char FAR * optval, int optlen);
  660.  
  661. int PASCAL FAR shutdown (SOCKET s, int how);
  662.  
  663. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  664.  
  665. /* Database function prototypes */
  666.  
  667. struct hostent FAR * PASCAL FAR gethostbyaddr(char FAR * addr,
  668.                           int len, int type);
  669.  
  670. struct hostent FAR * PASCAL FAR gethostbyname(char FAR * name);
  671.  
  672. struct servent FAR * PASCAL FAR getservbyport(int port, char FAR * proto);
  673.  
  674. struct servent FAR * PASCAL FAR getservbyname(char FAR * name,
  675.                           char FAR * proto);
  676.  
  677. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  678.  
  679. struct protoent FAR * PASCAL FAR getprotobyname(char FAR * name);
  680.  
  681. /* Microsoft Windows Extension function prototypes */
  682.  
  683. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  684.  
  685. int PASCAL FAR WSACleanup(void);
  686.  
  687. void PASCAL FAR WSASetLastError(int iError);
  688.  
  689. int PASCAL FAR WSAGetLastError(void);
  690.  
  691. BOOL PASCAL FAR WSAIsBlocking(void);
  692.  
  693. int PASCAL FAR WSAUnhookBlockingHook(void);
  694.  
  695. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  696.  
  697. int PASCAL FAR WSACancelBlockingCall(void);
  698.  
  699. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  700.                     char FAR * name, char FAR * proto,
  701.                     char FAR * buf, int buflen);
  702.  
  703. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  704.                     char FAR * proto, char FAR * buf,
  705.                     int buflen);
  706.  
  707. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  708.                      char FAR * name, char FAR * buf,
  709.                      int buflen);
  710.  
  711. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  712.                        int number, char FAR * buf,
  713.                        int buflen);
  714.  
  715. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  716.                     char FAR * name, char FAR * buf,
  717.                     int buflen);
  718.  
  719. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  720.                     char FAR * addr, int len, int type,
  721.                     char FAR * buf, int buflen);
  722.  
  723. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  724.  
  725. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  726.                    long lEvent);
  727.  
  728. /* Microsoft Windows Extended data types */
  729. typedef struct sockaddr SOCKADDR;
  730. typedef struct sockaddr *PSOCKADDR;
  731. typedef struct sockaddr FAR *LPSOCKADDR;
  732.  
  733. typedef struct sockaddr_in SOCKADDR_IN;
  734. typedef struct sockaddr_in *PSOCKADDR_IN;
  735. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  736.  
  737. typedef struct linger LINGER;
  738. typedef struct linger *PLINGER;
  739. typedef struct linger FAR *LPLINGER;
  740.  
  741. typedef struct in_addr IN_ADDR;
  742. typedef struct in_addr *PIN_ADDR;
  743. typedef struct in_addr FAR *LPIN_ADDR;
  744.  
  745. typedef struct fd_set FD_SET;
  746. typedef struct fd_set *PFD_SET;
  747. typedef struct fd_set FAR *LPFD_SET;
  748.  
  749. typedef struct hostent HOSTENT;
  750. typedef struct hostent *PHOSTENT;
  751. typedef struct hostent FAR *LPHOSTENT;
  752.  
  753. typedef struct servent SERVENT;
  754. typedef struct servent *PSERVENT;
  755. typedef struct servent FAR *LPSERVENT;
  756.  
  757. typedef struct protoent PROTOENT;
  758. typedef struct protoent *PPROTOENT;
  759. typedef struct protoent FAR *LPPROTOENT;
  760.  
  761. /*
  762.  * Windows message parameter composition and decomposition
  763.  * macros.
  764.  *
  765.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  766.  * when constructing the response to a WSAGetXByY()
  767.  */
  768. #define WSAMAKEASYNCREPLY(buflen,error)        MAKELONG(buflen,error)
  769. /*
  770.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  771.  * when constructing the response to WSAAsyncSelect()
  772.  */
  773. #define WSAMAKESELECTREPLY(event,error)        MAKELONG(event,error)
  774. /*
  775.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  776.  * to extract the buffer length from the lParam in the response
  777.  * to a WSAGetXByY().
  778.  */
  779. #define WSAGETASYNCBUFLEN(lParam)        LOWORD(lParam)
  780. /*
  781.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  782.  * to extract the error code from the lParam in the response
  783.  * to a WSAGetXByY().
  784.  */
  785. #define WSAGETASYNCERROR(lParam)        HIWORD(lParam)
  786. /*
  787.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  788.  * to extract the event code from the lParam in the response
  789.  * to a WSAAsyncSelect().
  790.  */
  791. #define WSAGETSELECTEVENT(lParam)        LOWORD(lParam)
  792. /*
  793.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  794.  * to extract the error code from the lParam in the response
  795.  * to a WSAAsyncSelect().
  796.  */
  797. #define WSAGETSELECTERROR(lParam)        HIWORD(lParam)
  798.  
  799. #endif    /* _WINSOCKAPI_ */
  800.